import { fromJS } from "immutable"

const defaultState = fromJS({
    isAdmin: null,
    userInfo:{
        username: ""
    }
})

const admin = (state = defaultState, action) => {
    if(action.type === "set") {
        // return {
            // isAdmin: action.payload.isAdmin,
            // userInfo: action.payload.userInfo
        // }
        return state.update("isAdmin", () => action.payload.isAdmin).updateIn(["userInfo", "username"], () => action.payload.userInfo.username)
    }
    if(action.type === "setIsAdmin") {
        // return {
        //     ...state,
        //     isAdmin: action.payload.isAdmin
        // }
        return state.update("isAdmin", () => action.payload.isAdmin);
    }
    if (action.type === "setUserInfo") {
        // return {
        //     ...state,
        //     userInfo: action.payload.userInfo
        // }
        return state.updateIn(["userInfo", "username"],() => action.payload.userInfo.username)
    }
    return state
}


export default admin